import axios from "axios";
import { useUserStore } from "@/stores/user";

const request = axios.create({
    baseURL: '/dev-api'
    // baseURL: import.meta.env.VITE_APP_BASE_URL
})

// 请求拦截
request.interceptors.request.use(config => {
    const userStore = useUserStore();
    if (userStore.token) {

      config.headers.Authorization = userStore.token;
    }
    return config
}, error => {
    return Promise.reject(error)   
})

// 响应拦截
request.interceptors.response.use(response => {
    return response
}, error => {
    return Promise.reject(error)
})

export default request;